/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.retails.utils;

/**
 *
 * @author sreejith
 */
public class AmountToWordUtil {
 
    /**
     * @param args the command line arguments
     */
    String[] ones = new String[]{
        "", " one", " two", " three", " four", " five", " six", " seven", " eight", " nine", " ten", " eleven", " twelve", " thirteen", " fourteen", " fifteen", " sixteen",
        " seventeen", " eighteen", " nineteen"
    };
    String[] tens = new String[]{
        "", "", " twenty", " thirty", " fourty", " fifty", " sixty", " seventy", " eighty", " ninenty"
    };

    String getNumberInWords(int n) {
        System.out.print( n + " = ");
        StringBuilder sbWrd = new StringBuilder();
        if (n == 0) {
            return "zero";
        }
        if (n < 0) {
            sbWrd.append("Negative");
            n = n * -1;
        }

        fillPart(sbWrd, (n/10000000) % 100, " crore");
        fillPart(sbWrd, (n/100000) % 100, " lack");
        fillPart(sbWrd, (n/1000) % 100, " thousand");
        fillPart(sbWrd, (n/100) % 10, " hundred");
        fillPart(sbWrd, n%100, "");

        return sbWrd.toString();
    }

    void fillPart(StringBuilder sbWrd, int n, String code) {
        sbWrd.append((n > 19) ? tens[n / 10] + ones[ n % 10] : ones[ n]);
        sbWrd.append(n > 0 ? code : "");
    }

    public static void main(String[] args) {
       AmountToWordUtil t = new AmountToWordUtil();
        System.out.println( t.getNumberInWords(12315) );
    }
}
